package io.github.luons.mediator.demo.controller;

import io.github.luons.mediator.core.spi.result.ApiResult;
import io.github.luons.mediator.core.spi.result.ResultData;
import io.github.luons.mediator.demo.dto.DemoSpecDto;
import io.github.luons.mediator.demo.entity.UserInfoDemo;
import io.github.luons.mediator.demo.service.UserInfoDemoService;
import io.github.luons.mediator.demo.vo.DemoInfoVo;
import io.github.luons.mediator.demo.vo.UserInfoDemoAggVo;
import io.github.luons.mediator.dsl.aspect.Pageable;
import io.github.luons.mediator.dsl.aspect.QueryFilter;
import io.github.luons.mediator.dsl.service.BaseQueryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * demo api
 *
 * @author : luons
 * @description demo
 */
@Slf4j
@RestController
@RequestMapping("/v1/regionId/{regionId}")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DemoTestController {

    private final UserInfoDemoService userDemoService;

    @Autowired
    @Qualifier(value = "userInfoDemoService")
    private BaseQueryService<UserInfoDemo> baseQueryService;


    /**
     * Demo post
     *
     * @param demoUniqId demoUniqId
     * @param demoSpec   demoSpec
     */
    @PostMapping("/demo/{demoUniqId}/")
    public ApiResult<ResultData<String>> demoPost(@PathVariable String demoUniqId,
                                                  @Valid @RequestBody DemoSpecDto demoSpec) {
        return ApiResult.success(new ResultData<>("uniqId"));
    }

    /**
     * Demo get
     *
     * @param demoUniqId demoUniqId
     * @param demoName   demoName
     */
    @GetMapping("/demo/{demoUniqId}/info")
    public ApiResult<ResultData<List<DemoInfoVo>>> describeDemoInfoList(@PathVariable String demoUniqId,
                                                                        @RequestParam(name = "demoName") Integer demoName) {
        List<DemoInfoVo> list = new ArrayList<>();
        return ApiResult.success(new ResultData<>(list));
    }

    /**
     * Demo post
     */
    @Pageable
    @QueryFilter(UserInfoDemo.class)
    @RequestMapping(value = "/demoUser", method = {RequestMethod.POST, RequestMethod.GET})
    public ApiResult<ResultData<List<UserInfoDemo>>> demoUser() {
        List<UserInfoDemoAggVo> list00 = baseQueryService.findAndSearchByFilters(UserInfoDemoAggVo.class);

        List<UserInfoDemo> list0 = baseQueryService.findAndSearchByFilters();
        List<UserInfoDemo> list1 = userDemoService.findAllUserList();
        List<UserInfoDemo> list2 = userDemoService.findAndSearchByEntity(null);
        List<UserInfoDemo> list3 = userDemoService.findAndSearchByFilters();
        return ApiResult.success(new ResultData<>(list0));
    }

}
